package com.wind.plugin.openAction;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;

public class openAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        // TODO: insert action logic here
        Project project = e.getProject();
        if (project == null) return;

        // 获取选中的文件
        VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);

        if (file != null && file.getName().endsWith(".xml")) {
            // 创建并显示自定义编辑器
            FileEditorManager editorManager = FileEditorManager.getInstance(project);
            FileEditor customEditor = new CustomTextEditorProvider().createEditor(project, file);
            if (customEditor != null) {
                editorManager.openFile(file, true);
            }
        }
    }

}
